var RecordSearchForm = function () {
  var template = /* html */ `
  <div v-loading.fullscreen.lock="loading" class="search-form">
    <sys-common-search request-url="materialSelectFilter/getMaterialSelectData" :request-data="requestData" :search="search"
      :search-field="searchField" label-width="100px" input-width="170px" ref="searchForm">
      <template slot="prepend">
        <el-form-item label="制单日期">
          <el-date-picker style="width:219px" v-model="search.startDate" value-format="timestamp" :editable="false"
            :clearable="false" :picker-options="startDateOption"></el-date-picker>
          -
          <el-date-picker style="width:219px" v-model="search.endDate" value-format="timestamp" :editable="false"
            :clearable="false" :picker-options="endDateOption"></el-date-picker>
        </el-form-item>
      </template>
      <template slot="append">
        <el-form-item label="客户名称">
          <el-select filterable clearable style="width:170px" v-model="search.customerName" placeholder="请选择客户">
            <el-option v-for="customer in customerList" :key="customer" :label="customer" :value="customer"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="制单人员">
          <el-select filterable clearable style="width:170px" v-model="search.createUser" placeholder="请选择制单人">
            <el-option v-for="createUser in createUserList" :key="createUser.id" :label="createUser.name" :value="createUser.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出入库">
          <el-select clearable style="width:170px" v-model="search.type" placeholder="请选择出入库类型">
            <el-option v-for="(type,index) in typeList" :key="'type_'+index" :label="type.label" :value="type.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查询类型">
          <el-select clearable style="width:170px" v-model="search.queryType" placeholder="请选择查询类型">
            <el-option v-for="(queryType,index) in queryTypeList" :key="'queryType_'+index" :label="queryType.label" :value="queryType.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态" v-if="type==='record'">
          <el-select clearable style="width:170px" v-model="search.status" placeholder="请选择订单状态">
            <el-option v-for="(status,index) in statusList" :key="'status_'+index" :label="status.label" :value="status.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="来源" v-if="type==='record'">
          <el-select filterable clearable style="width:170px" v-model="search.source" placeholder="请选择订单状态">
            <el-option v-for="(sourceType,index) in sourceTypeList" :key="'sourceType_'+index" :label="sourceType.label" :value="sourceType.value"></el-option>
          </el-select>
        </el-form-item>
      </template>
    </sys-common-search>
  </div>
  `;

  return {
    mixins:[datePickerOptionsMixin('startDate','endDate')],
    props: {
      search: {
        type: Object,
        required: true
      },

      type: {
        type: String,
        default: "record"
      }
    },

    data: function () {
      return {
        loading: false,
        searchField: ['orderId', 'companyOrderId', 'factoryNo', 'customerNo'],
        customerList: [],
        createUserList: [],
        typeList: i18n.getDropDown('warehouseInOutRecord.type', [1, 2]),
        queryTypeList: i18n.getDropDown('warehouseInOutRecord.queryType', [1, 2]),
        statusList: i18n.getDropDown('warehouseInOutRecord.status', [0, 1, 2]),
        sourceTypeList: i18n.getDropDown('common.warehouseSourceType', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]),
        requestData: {
          type: 5,
          warehouseType: 1
        }
      };
    },

    created: function () {
      this.loading = true;
      var self = this;
      Promise.all([
        this.setCustomerList(),
        this.setCreateUserList()
      ]).then(function () {
        self.loading = false;
      }).catch(function () {
        self.loading = false;
      });
    },

    methods: {
      setCustomerList: function () {
        var self = this;
        return ajaxRequest("warehouse/getCustomerNameByWarehouse").then(function (customerList) {
          var customers = [];
          for (var i = 0; i < customerList.length; i++) {
            var customer = customerList[i];
            var warehouseTypeList = customer.warehouseTypeList;
            if (warehouseTypeList.indexOf("1") === -1) {
              continue;
            }

            var userName = customer.userName;
            if (userName.trim() === '') {
              continue;
            }
            customers.push(userName);
          }
          self.customerList = customers;
          return customerList;
        });
      },

      setCreateUserList: function () {
        var self = this;
        return ajaxRequest("warehouse/getWarehouseInOutCreateUser").then(function (createUserList) {
          var createUsers = [];
          for (var i = 0; i < createUserList.length; i++) {
            var createUser = createUserList[i];
            var warehouseTypeList = createUser.warehouseTypeList;
            if (warehouseTypeList.indexOf("1") === -1) {
              continue;
            }
            createUsers.push({
              id: createUser.id,
              name: createUser.userName
            });
          }
          self.createUserList = createUsers;
          return createUserList;
        });
      }
    },

    components: {
      SysCommonSearch: SysCommonSearch
    },

    template: template
  };
}();